// 计时工资

<template>
  <view>
    <mes-search
      placeholder="关键词"
      v-model="postForm.keyword"
      @search="resetPaging(), getData()"
    ></mes-search>
    <mes-tip v-if="noData"></mes-tip>
    <mes-nav-index :form="mesNavForm"></mes-nav-index>
  </view>
</template>

<script>
export default {
  data() {
    return {
      noData: false,
      mesNavForm: {
        tapItem: (item) => {
          uni.navigateTo({
            url: `/pages/home/time_salary/detail?form=${JSON.stringify(
              item.row
            )}`
          })
        },
        items: []
      },
      // 筛选条件列表
      filterList: [
        {
          name: '职员'
        }
      ],
      hasMore: true,
      postForm: {
        page: 1,
        limit: 10,
        keyword: ''
      }
    }
  },
  onShow() {
    this.resetPaging()
    this.getData()
  },
  onReachBottom() {
    if (!this.hasMore) return
    this.postForm.page++
    this.getData()
  },
  methods: {
    // 重置分页
    resetPaging() {
      this.hasMore = true
      this.postForm.page = 1
      this.mesNavForm.items = []
    },
    // 获取列表
    async getData() {
      let res = await this.$api.source.staff_member.index(this.postForm)
      if (res.code == 200) {
        let list = []
        res.data.list.forEach((item) => {
          list.push({
            row: item,
            title: item.name,
            body: [
              {
                name: '',
                value: item.men_code
              }
            ]
          })
        })
        this.hasMore = res.data.list.length ? true : false
        this.mesNavForm.items = [...this.mesNavForm.items, ...list]
        this.noData = !this.mesNavForm.items.length
      }
    }
  }
}
</script>

<style>
page {
  padding: 92rpx 0 50rpx;
}
</style>
